package com.findmeastore.dao.impl;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.dao.support.DataAccessUtils;
import org.springframework.orm.hibernate3.HibernateTemplate;

import com.findmeastore.bo.CategoryBo;
import com.findmeastore.dao.ICategoryDAO;

public class CategoryDAOImpl implements ICategoryDAO{
	private HibernateTemplate hibernateTemplate;
	public void setSessionFactory(SessionFactory sessionFactory){
		this.hibernateTemplate = new HibernateTemplate(sessionFactory);
	}
	
	public Integer getTotalCategoryCount(){
		return DataAccessUtils.intResult(hibernateTemplate.find("select count(*) from CategoryBo"));
	}
	
	@SuppressWarnings("unchecked")
	public List<CategoryBo> getAllCategories() {
		return hibernateTemplate.find("from CategoryBo");
	}

	public CategoryBo getCategoryById(Integer id) {
		return (CategoryBo)hibernateTemplate.get(CategoryBo.class, id);
	}

	public void saveCategory(CategoryBo categoryBo) {
		hibernateTemplate.saveOrUpdate(categoryBo);
	}
}
